/**
 * 工具函数
 */
require("../../lib/fonts/iconfont.css")
require("../../fonts/iconfont.css")
function isPhone(num) {
    return /^1[3-9]\d{9}$/.test(num);
}
function isPassword(pwd) {
    return /^[a-zA-Z]\w{5,17}$/.test(pwd)
}
//弹框
function toast(font = "success", msg = "操作成功", time = 3000) {
    let div = document.createElement("div");
    div.innerHTML = `<span class="iconfont icon-${font}"></span><p class="mt20">${msg}</p>`
    div.className = "toast-warpper"
    document.body.appendChild(div)
    setTimeout(function () {
        div.remove()
    }, time)
}
function tabbar(msg) {
    let div = document.createElement("div");
    div.className = "tabbar-item";
    div.innerHTML = `
        <a href="./home.html" class="dpflex ${msg=="home"?"active":""}">
            <span class="icon iconfont icon-home"></span>
            <p>首页</p>
        </a>
        <a href="./course.html" class="dpflex ${msg=="course"?"active":""}">
            <span class="icon iconfont icon-sport"></span>
            <p>运动</p>
        </a>
        <a href="./mine.html" class="dpflex ${msg=="mine"?"active":""}">
            <span class="icon iconfont icon-mine"></span>
            <p>我的</p>
        </a>
    `
    document.querySelector("footer").appendChild(div)
}
// 补零
function addZero(num){
    return num<10?"0"+num:num
}
function formatDate(date){
    let now=new Date(date);
    let y=now.getFullYear()
    let m=now.getMonth()+1
    let d=now.getDate()
    return [y,addZero(m),addZero(d)].join("-")
}
// 接口
let url = "http://139.9.177.51:8099"
window.$utils = {
    isPhone,
    isPassword,
    toast,
    url,
    tabbar,
    addZero,
    formatDate,
}
